import content from '../../api/content'
const store = {
    state:{
        strategy:[],
        articles:[],
        article:'',
        focusImg:[]
    },
    getters: {
        getStrategy(state){
            return state.strategy
        },
        getArticles(state){
            return state.articles
        },
        getArticle(state){
            return state.content
        },
        getFocusImg(state){
            return state.focusImg
        }
    },
    mutations: {
        strategy(state, data){
           //遍历strategy 列表
           state.strategy = data;     
        },
        articles(state, data){
            state.articles = data;
        },
        article(state, data){
            state.article = data;
        },
        focusImg(state,data){
            state.focusImg = data.data;
        },
        udpateFocusImg(state,data){
            state.focusImg.forEach(function(v,k){
                if(v.id === data.id){
                    v.path = data.path
                }
            })
        },
        delFocusImg(state,id){
           state.focusImg.forEach(function(v,k){
                if(v.id === id){
                    v.path = ''
                }
            })
        }
    },
    actions: {
        getStrategy({commit},data){
            content.getStrategy( strategy => {
                commit('strategy',strategy);
            })
        },
        getArticles({commit},data){
            content.getArticles( articles => {
               commit('articles', articles);
            },data);
        },
        getArticle({commit},data){
            content.getArticle( content => {
                commit('article', content)
            },data)
        },
        getFocusImg({commit},data){
            content.getFocusImg(content => {
                commit('focusImg',content);
            })
        },
        updateFocusImg({commit},data){
            content.updateFocusImg(content=>{
                commit('udpateFocusImg',content);
            },data)
        },
        delFocusImg({commit},id){
            content.delFocusImg(content => {
                commit('delFocusImg',id)
            },id)
        },
        //攻略管理相关action
         updateStrategy({commit},data){
            content.upateStrategy(content => {
                commit('strategy',id)
            },data)
         }
        //攻略管理相关action
    }
}

export default store;